<template>
  <div class="container " id="Home">
    <el-card class="teachPreparepCard">
		<div sole="header" class="flex-box between padTop padBtm">
			<b>学科成长</b>
			<div class="page">
				<el-button type="text"  plain @click="changeThatWeek(-1)" class="el-icon-arrow-left clPad" />
				<span>{{TEACHERWeekVal}}</span>

        	<el-button  plain type="text" @click="changeThatWeek(1)" class="el-icon-arrow-right clPad" />
			</div>
		</div>

    <div class="teachCon t-center">
        <div  class=" t-left padTop padBtm" v-if="TEACHERList.records.length">
             <router-link tag="div" :to="{name:'teachDesignDetails',query:{designId:tarin.id}}"
              v-for='(tarin , i ) in TEACHERList.records' :key='i' class="prepareList ov"
            >
               <span>{{tarin.title}}</span>
               <div class="fl_box fr" >
                 {{tarin.createTime}}
               </div>
             </router-link>
          </div>
          <noPerpare v-else></noPerpare>
          <div class=''>
            <el-button @click='$router.push(`/home/morePerpareLesson`)'>查看案例</el-button>
            <el-button type="primary" @click='$router.push(`/createResult/uploadLessonPlan`)' >上传教学设计</el-button>
           <!-- <el-button>集体备课</el-button> -->
            </div>
          <Pagination float='right'  :total="TEACHERList.records.length" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />
    </div>
	</el-card>

  <el-card class="trainingPrepareCard">

  	<div sole="header" class="flex-box between padTop padBtm">
  		<b>教师成长</b>
  		<div class="page">
  			<el-button  plain type="text" @click="changeThatWeek(-1,'TRAINER')" class="el-icon-arrow-left clPad" />
  			<span>{{TRAINERWeekVal}}</span>
  		  <el-button  plain type="text" @click="changeThatWeek(1,'TRAINER')" class="el-icon-arrow-right clPad" />
  		</div>
  	</div>
    <div class="trainingCon">
          <div class="prepareList padTop padBtm"
            v-if="TRAINERList.records.length">
             <router-link tag="div" v-for='(tarin , i ) in TRAINERList.records' :key='i' class="ov" :to="{name:'teachDesignDetails',query:{designId:tarin.id}}">
               <span>{{tarin.title}}</span>
               <div class="fl_box fr" >
                 {{tarin.createTime}}
               </div>
             </router-link>
          </div>
          <noPerpare v-else></noPerpare>
          <el-button type="primary" @click='$router.push(`/createResult/uploadLessonPlanTrainer`)'>上传教学设计</el-button>
          <Pagination float='right'  :total="TRAINERList.records.length" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />

    </div>

  </el-card>

  </div>
</template>

<script>
  import {parseTime} from '@/utils'
  import Pagination from '@/components/Pagination'
  import noPerpare from './components/noPerpare'
  var oneDayTime = 24*60*60*1000 ;
  var xs = '{y}-{m}-{d}', weekStr = ' / '
  var now = new Date();
  var nowTime = now.getTime() ;
  var day = now.getDay();
  var MondayTime = nowTime - (day-1)*oneDayTime ;//显示周一
  var SundayTime =  nowTime + (7-day)*oneDayTime ;//显示周日
  var oneDay = parseTime(MondayTime,xs)
  var sunDay = parseTime(SundayTime,xs)
  var thatWeek = oneDay + weekStr + sunDay

export default {
  name: 'Home',
  data() {
      return {
        TEACHERWeekVal:thatWeek,
        TRAINERWeekVal:thatWeek,
        indWeekDayObj:{
        MondayTime,
        SundayTime,
        },
        listQuery:this.$store.state.app.pager,
        prepareLessonType:'TEACHER',
        // TRAINERList:[]
      }
  },
  components:{
   noPerpare,
   Pagination
  },
  created() {
    let condition = this.addTimeStr({startTime:oneDay,endTime:sunDay})
    this.getPreparePage({prepareLessonType:'TEACHER',...condition}) //教师
    this.getPreparePage({prepareLessonType:'TRAINER',...condition}) //培训师
  },
  watch:{
     // ['$store.state.personPrepareLesson.prepareLesson.TEACHER']:{
     //   handler: function(val){
     //   //this[this.prepareLessonType] =  val
     //   this[this.prepareLessonType] = this.$store.state.personPrepareLessonTEACHER
     // },
     //  immediate: true,
     //  },
     //  ['$store.state.personPrepareLesson.prepareLesson.TRAINER']:{
     //    handler: function(val){
     //    //this[this.prepareLessonType] =  val
     //    this[this.prepareLessonType] = this.$store.state.personPrepareLesson.TRAINER
     //  },
     //   immediate: true,
     //   }
  },
  computed:{
    TEACHERList(){
      //this.TEACHERList = this.$store.state.personPrepareLesson.TEACHER
      return this.$store.state.personPrepareLesson.TEACHER
    },
    TRAINERList(){
       return this.$store.state.personPrepareLesson.TRAINER
    },
  },
  methods: {
    addTimeStr(condition){
      var  end =' 23:59:59', star =' 00:00:00'
      condition.startTime = condition.startTime + star;
      //let end = parseTime((new Date(condition.endTime).getTime() + oneDayTime ) -1)
      condition.endTime =  condition.endTime + end
      return condition
    },
  changeThatWeek(add,dataName='TEACHER'){
     this.prepareLessonType = dataName
    this.indWeekDayObj.MondayTime +=(add*(oneDayTime*7))
    this.indWeekDayObj.SundayTime +=(add*(oneDayTime*7))
    const startTime = parseTime(this.indWeekDayObj.MondayTime,xs)
    const endTime = parseTime(this.indWeekDayObj.SundayTime,xs)
    this[dataName+'WeekVal'] = startTime + weekStr + endTime
    // this.TRAINERWeekVal = this.indWeekDayObj.SundayTime+(add*(oneDayTime*7))
    let condition =   {...this.addTimeStr({endTime,startTime}),prepareLessonType:dataName}
    this.getPreparePage(condition)
  },
  getPreparePage(conditions){
      let condition = Object.assign({
          endTime:'',
          startTime:'',
          userId:this.$store.getters.userId,
        },conditions)
      let params = {
        condition,
       "orderBys": [
        {
          "asc": true,
          //"column": ""
        }
      ],
      "pager": {
        "page": this.listQuery.page,
        "pageSize": this.listQuery.pageSize
      }
    }
    this.condition = condition
    this.$store.dispatch('personPrepareLesson/Page',{params,stateName:condition.prepareLessonType})
    this.prepareLessonType = condition.prepareLessonType+'List'
  },
  prepareLessons(){
    this.$router.push({path:`/createResult/uploadLessonPlan`})
  },
  getList(page,limit) {
    
   this.getPreparePage(this.condition)
  //   this.listLoading = true
  //   fetchList(this.listQuery).then(response => {
  //     this.list = response.data.items
  //     this.total = response.data.total
  //     this.listLoading = false
  //   })
  }
  }
}
</script>

<style lang="scss" scoped>
  .teachPreparepCard{
    margin-top:40px;

  }
  .prepareList{

      padding:4px;
      border-top: 1px solid #f2f3f4;;
     // box-shadow: 1px 5px 9px 0px #d9dce2;
    }
  .el-calendar {
    & /deep/ &-table {
      .el-calendar-day {
        height: 130px;
      }
    }
  }
</style>
